package day01;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author feng
 * @Date 2021/10/13 8:29
 *    有返回值
 */
public class CallableTest implements Callable {

    private int ticket = 10;
    @Override
    public String call() throws Exception {

        for (int i = 0; i <ticket ; i++) {
            if (ticket>0){
                System.out.println("售出="+ticket--);
            }
        }

        return "票已卖完";
    }


    public static void main(String[] args) {
        CallableTest call = new CallableTest();
        CallableTest ca2 = new CallableTest();
        FutureTask<String> futureTask1 = new FutureTask(call);
        FutureTask<String> futureTask2 = new FutureTask(ca2);
        Thread t1 = new Thread(futureTask1);
        Thread t2 = new Thread(futureTask2);
        t1.start();
        t2.start();

    }
}
